package com.onenine.app.view.popwin;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;

import com.onenine.app.R;

/**
 * 创建时间：2018/5/18 0018 11:10
 * 创建人：fly
 * 功能描述：图片或视频弹层
 */
public class MediaPopWindow extends BottomPopWindow implements View.OnClickListener {

    public static final int IMAGE_TYPE = 0;//图片
    public static final int VIDEO_TYPE = 1;//视频
    private OnTakePictureCallback mCallback;
    private int mMediaType;

    public interface OnTakePictureCallback {
        void onCamera(int mediaType);

        void onSelectPicture(int mediaType);
    }

    public MediaPopWindow(Activity activity, OnTakePictureCallback callback) {
        super(activity);
        mCallback = callback;
    }

    public MediaPopWindow(Activity activity, int mediaType, OnTakePictureCallback callback) {
        super(activity);
        mMediaType = mediaType;
        mCallback = callback;
    }

    @Override
    public void onClick(View v) {
        if (v == getContentView() || v.getId() == R.id.btn_cancel) {
            dismiss();
        } else if (v.getId() == R.id.btn_camera) {
            //拍照
            dismiss();
            if (mCallback != null) {
                mCallback.onCamera(mMediaType);
            }
        } else if (v.getId() == R.id.btn_album) {
            //从相册选择
            dismiss();
            if (mCallback != null) {
                mCallback.onSelectPicture(mMediaType);
            }
        }
    }

    @Override
    protected View genContentView() {
        View bottomView = LayoutInflater.from(mActivity)
                .inflate(R.layout.layout_media_popwin, null, false);
        bottomView.setOnClickListener(this);
        bottomView.findViewById(R.id.btn_camera).setOnClickListener(this);
        bottomView.findViewById(R.id.btn_album).setOnClickListener(this);
        bottomView.findViewById(R.id.btn_cancel).setOnClickListener(this);
        return bottomView;
    }

}
